package cn.bone.ou.scheduled.job;

import cn.bone.ou.data.mapper.OpLoggerDetailMapper;
import cn.bone.ou.data.mapper.OpLoggerMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

@Component
@Slf4j
public class OpLoggerExpireJob {

    @Resource
    private OpLoggerMapper loggerMapper;
    @Resource
    private OpLoggerDetailMapper detailMapper;

    /**每小时执行一次,删除一个月之前的日志*/
    public void execute(){
        Date date = new Date();
        Date expireTime = DateUtils.addDays(date, -30);
        int a1 = loggerMapper.deleteExpire(expireTime);
        int a2 = detailMapper.deleteExpire(expireTime);
        String msg = "删除过期日志-> 日志["+a1+"]条,日志详情["+a2+"]";
        log.info(msg);
    }
}
